import g


# 创建玩家信息
async def creatPlayer(binduid, sid, ip, extdata, gateway_url=None):
    _nt = g.C.NOW()

    _oid = g.C.getObjectId(is_str=True)
    uid = str(sid) + '_' + str(_oid)
    if "yace" in binduid:
        uid += "yace"
    uuid = g.C.getUUIDByDBID(str(_oid))
    _userInfo = {
        "_id": _oid,
        'uid': uid,
        'uuid': uuid,  # 玩家唯一uuid
        "createip": ip,  # 创建账号时的ip
        "lastloginip": ip,  # 最后一次登录时的ip
        'binduid': binduid,  # 玩家账号

        "sid": sid,  # 区服id
        # "name": g.C.getUniqCode(),  # 玩家名
        "name": str(_oid),  # 玩家名
        'ctime': _nt,  # 玩家创号时间
        "logintime": _nt,  # 最后一次登录时间
        "loginnum": 1,  # 累计登陆天数
        "ext_servername": "",  # 区服名
        **extdata,
    }

    # 创建玩家 必须要实时写库
    await g.Model.UserInfo.insertOne(uid, _userInfo)
    if "_id" in _userInfo:
        _userInfo["_id"] = str(_userInfo["_id"])

    return _userInfo
